
 
<html>    
<title>Order Information Page</title> 
<head>
<link href="../includes/calendar/jquery.datepick.css" rel="stylesheet" type="text/css" />   

</head>
<body>
<?php 

/*

***************************************
*                                     *
* Copyright 2011 David Matthew Pugh   *
* Contact Info:thebravedave@gmail.com *
*                                     *
***************************************

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

require_once "../services/webservices.php"; 
require_once "index.php";
require_once "../Pagination.php";
require_once("../getbrowser.php");
?>

<script type="text/javascript" src="../includes/calendar/jquery.min.js"></script>
<script type="text/javascript" src="../includes/calendar/jquery.datepick.js"></script>
<script type="text/javascript">
$(function() {

    $('#inlinedatepicker').datepick({onSelect: showDate});


});
function showDate(date) 
{
   
    document.getElementById("date").value = date;
}

function checkdateform()
{
        
        
        go=true;
        if(document.getElementById("date").value=='')
        {
            alert("Please choose a date from the calendar");
            
            return false;
        }
        else
        {
            document.forms("testform").submit();
        }
       
}


</script>


<br /> 
<br />


<script language="JavaScript" src="../includes/calendar/calendar_us.js"></script>
<link rel="stylesheet" href="../includes/calendar/calendar.css">

<link href="../includes/admin.css " rel="stylesheet" type="text/css" />

<?php

if(isset($_GET['order_command']))
{
    if($_GET['order_command']=="getorderbyorderid")
    {
   
?>                                                  

        <b>Get Order By Order ID</b><br />
        <div class="leftfloatbar">
        <form action="orderdetails.php" method="POST" id="getorderbyorderidform" name="getorderbyorderidform">   
        <input type="text" id="order_id" name="order_id" size="35" >
        <input type="submit" value="Submit">
        </form>
        <hr>
        <br />
        </div>
        <br /><br /><br />     <br /><br /><br />   
<?php

     }

    if($_GET['order_command']=="getincompleteorders")
    {   

        $limit = $_GET['limit'];
        $page = $_GET['page'];
        $targetPage = "orders.php";
        $getrequest = new payment();
        $getrequest->page = $page;
        $getrequest->limit = $limit;
        $getresponse = $getrequest->getpaymentbyincomplete();
        $xml = new SimpleXMLElement($getresponse);
        if($xml->Item_Count !=0)
        {         
            $Pagination = new Pagination();
            $Pagination->setLimit($limit);
            $Pagination->setPage($page);
            $Pagination->setTargetPage($targetPage);
            $Pagination->setTotalItems($xml->Item_Count);
            $Pagination->addToUrlVarArray("order_command=getincompleteorders");
            $Pagination->addToUrlVarArray("limit=$limit");
            $Pagination->addToUrlVarArray("Page=$page");
            $Pagination->setUrlVariables();
            print "<b>Incomplete Orders</b><br /><br />";
            foreach($xml->Item as $itemcount)
            {
                $order_id = $itemcount->order_id;
                $first_name = $itemcount->first_name;
                $payment_type = $itemcount->payment_type;
                $last_name = $itemcount->last_name;
                $amount = (double)$itemcount->amount;
                $amount = number_format($amount, 2, '.', '');   
                $email = $itemcount->email;
                $payment_date = $itemcount->payment_date;
                ?>
                 
                <div class="doubleborderrightmargin">
                
                <b>Order_ID:</b> <?php echo $order_id; ?><br />
                <b>Payment Type:</b> <?php echo $payment_type;?><br />
                <b>Payment Amount:</b> <?php echo "$" . $amount;?><br />                        
                <b>First Name:</b> <?php echo $first_name;?><br />          
                <b>Last Name:</b> <?php echo $last_name;?><br />         
                <b>Payment Date:</b> <?php echo $payment_date;?><br />    
                <br />

                <form action="./orderdetails.php" method="POST">
                <input type="hidden" name="order_id" value="<?php echo $order_id;?>"> 
                <input type="submit" name="submit" value="Get This Order">
                </form>  
               </div>
               
            <?php 
            }  
            echo $Pagination->getEmbeddedCssStyling();
            $Pagination->getPaginationLinkBar();  
        }
        
        
        
        
    }
    if($_GET['order_command']=="getcompletedorders")
    {  

        $limit = $_GET['limit'];
        $page = $_GET['page'];
        $targetPage = "orders.php";
        $getrequest = new payment();
        $getrequest->limit = $limit;
        $getrequest->page = $page;
        $getresponse = $getrequest->getpaymentbycomplete();
        $xml = new SimpleXMLElement($getresponse);
        if($xml->Item_Count !=0)
        {
            $Pagination = new Pagination();
            $Pagination->setLimit($limit);
            $Pagination->setPage($page);
            $Pagination->setTargetPage($targetPage);
            $Pagination->setTotalItems($xml->Item_Count);
            $Pagination->addToUrlVarArray("order_command=getcompletedorders");
            $Pagination->addToUrlVarArray("limit=$limit");
            $Pagination->addToUrlVarArray("Page=$page");
            $Pagination->setUrlVariables();
            echo '<div class="doubleborderrightmargin">'; 
            print "<b>Completed Orders</b><br /><br />";
           
            foreach($xml->Item as $itemcount)
            {
                $order_id = $itemcount->order_id;
                $first_name = $itemcount->first_name;
                $payment_type = $itemcount->payment_type;
                $last_name = $itemcount->last_name;
                $amount = (double)$itemcount->amount;
                $amount = number_format($amount, 2, '.', '');   
                $email = $itemcount->email;
                $payment_date = $itemcount->payment_date;
                ?>
                <b>Order_ID:</b> <?php echo $order_id; ?><br />
                <b>Payment Type:</b> <?php echo $payment_type;?><br />
                <b>Payment Amount:</b> <?php echo "$" . $amount;?><br />                        
                <b>First Name:</b> <?php echo $first_name;?><br />          
                <b>Last Name:</b> <?php echo $last_name;?><br />         
                <b>Payment Date:</b> <?php echo $payment_date;?><br />    
                <br />

                <form action="./orderdetails.php" method="POST">
                <input type="hidden" name="order_id" value="<?php echo $order_id;?>"> 
                <input type="submit" name="submit" value="Get This Order">
                </form>  
                </div>
            <?php 
            }
            $Pagination->getPaginationLinkBar();  
        }
        else
        {
            print "No completed orders found.";    
        }   
        
        
        
    }
    if($_GET['order_command']=="getrefundedorders")
    {  

        $limit = $_GET['limit'];
        $page = $_GET['page'];
        $targetPage = "orders.php";
        $getrequest = new payment();
        $getrequest->page = $page;
        $getrequest->limit = $limit;
        $getresponse = $getrequest->getpaymentbyreturned();    
        $xml = new SimpleXMLElement($getresponse);
        if($xml->Item_Count !=0)
        {
            
            $Pagination = new Pagination();
            $Pagination->setLimit($limit);
            $Pagination->setPage($page);
            $Pagination->setTargetPage($targetPage);
            $Pagination->setTotalItems($xml->Item_Count);
            $Pagination->addToUrlVarArray("order_command=getrefundedorders");
            $Pagination->addToUrlVarArray("limit=$limit");
            $Pagination->addToUrlVarArray("Page=$page");
            $Pagination->setUrlVariables();
            
            print "<b>Refunded Orders</b><br /><br />";
           
            foreach($xml->Item as $itemcount)
            {
                
                $order_id = $itemcount->order_id;
                $first_name = $itemcount->first_name;
                $payment_type = $itemcount->payment_type;
                $last_name = $itemcount->last_name;
                $amount = (double)$itemcount->amount;
                $amount = number_format($amount, 2, '.', '');   
                $email = $itemcount->email;
                $payment_date = $itemcount->payment_date;
                ?>
                
                <div class="doubleborderrightmargin">
                <b>Order_ID:</b> <?php echo $order_id; ?><br />
                <b>Payment Type:</b> <?php echo $payment_type;?><br />
                <b>Payment Amount:</b> <?php echo "$" . $amount;?><br />                        
                <b>First Name:</b> <?php echo $first_name;?><br />          
                <b>Last Name:</b> <?php echo $last_name;?><br />         
                <b>Payment Date:</b> <?php echo $payment_date;?><br />    
                <br />

                <form action="./orderdetails.php" method="POST">
                <input type="hidden" name="order_id" value="<?php echo $order_id;?>"> 
                <input type="submit" name="submit" value="Get This Order">
                </form>  
                </div>
            
            <?php 
            }   
            echo $Pagination->getEmbeddedCssStyling();
            $Pagination->getPaginationLinkBar(); 
        }
        else
        {
            print "No returned orders found.";    
        }   
        
        
        
    }
    if($_GET['order_command'] == "getordersbydate")
    {
        
?>     
        <b>Get Order By Date</b><br />
        <div class="leftfloatbar"> 
        <form action="./orders.php" method="GET" id="testform" name="testform">
            <div id="inlinedatepicker"></div>
            <input type="hidden" name="page" value="<?php echo $_GET['page']; ?>">
            <input type="hidden" name="order_command" value="getordersbydate" />
            <input type="hidden" name="limit" value="<?php echo $_GET['limit']; ?>">        
            <!-- calendar attaches to existing form element -->
            <input type="hidden" id="date" name="date" /><br />            
            <input type="submit" name="submitgetordersbydate" value="submit date" onclick="javascript: checkform();"/> 
        </form>
        </div>
         <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />      
         <br /><br /><br />        
<?php
    

        if(isset($_GET['submitgetordersbydate']))
        {
            
            
          
            $date = $_GET['date'];
            $datearray = explode(" ", $date);
            
            //have to get browser info because the calendar data is returned in a different order in Iexplorer. We process the dataarray differently
            $browserarray = browser_info();
            $browser = "";
            foreach($browserarray as $key => $value)
            {
                $browser = $key;
            }
            if($browser == "msie")
            {
                $month = trim($datearray[1]);
                $integermonth = 0;
                $day = trim($datearray[2]);
                $year = trim($datearray[5]);   
            }
            else
            {
                $month = trim($datearray[1]);
                $integermonth = 0;
                $day = trim($datearray[2]);
                $year = trim($datearray[3]);   
                
            }
            echo '<br /><br />';
            
            if($month == "Jan")
            {
               $integermonth = 1; 
            }
            else if($month == "Feb")
            {
               $integermonth = 2; 
            }
            else if($month == "Mar")
            {
               $integermonth = 3; 
            }
            else if($month == "Apr")
            {
               $integermonth = 4; 
            }
            else if($month == "May")
            {
               $integermonth = 5; 
            }
            else if($month == "Jun")
            {
               $integermonth = 6; 
            }
            else if($month == "Jul")
            {
               $integermonth = 7; 
            }
            else if($month == "Aug")
            {
               $integermonth = 8; 
            }
            else if($month == "Sep")
            {
               $integermonth = 9;  
            }
            else if($month == "Oct")
            {
               $integermonth = 10; 
            }
            else if($month == "Nov")
            {
               $integermonth = 11; 
            }
            else if($month == "Dec")
            {
               $integermonth = 12; 
            }
           
            $formatted = $year . "-" . $integermonth . "-" . $day;
            
          
            $limit = $_GET['limit'];
            $page = $_GET['page'];
            $Payment = new payment();
            $Payment->limit = $limit;
            $Payment->page = $page;
            $Payment->payment_date = $formatted;
            $paymentReturn = $Payment->getpaymentbydate();
            $paymentXml = new SimpleXMLElement($paymentReturn);
            $Item_Count = $paymentXml->Item_Count;
           
            
            $targetPage = "orders.php";
            $Pagination = new Pagination();
            $Pagination->setLimit($limit);
            $Pagination->setPage($page);
            $Pagination->setTargetPage($targetPage);
            $Pagination->setTotalItems($Item_Count);
            $Pagination->addToUrlVarArray("order_command=getordersbydate");
            $Pagination->addToUrlVarArray("submitgetordersbydate=submit");
            $Pagination->addToUrlVarArray("limit=$limit");
            $Pagination->addToUrlVarArray("Page=$page");
            
               
            $Pagination->addToUrlVarArray("date=$date");
           
            $Pagination->setUrlVariables();
            
            echo '<br /><br />';
            foreach($paymentXml->Item as $paymentItem)
            {
                $order_id = $paymentItem->order_id;
                $orderstatus = $paymentItem->order_status;
                $first_name = $paymentItem->first_name;
                $payment_type = $paymentItem->payment_type;
                $last_name = $paymentItem->last_name;
                $amount = (double)$paymentItem->amount;
                $amount = number_format($amount, 2, '.', '');   
                $email = $paymentItem->email;
                $payment_date = $paymentItem->payment_date;
                ?>
                <div class="doubleborderrightmargin">
                <b>Order_ID:</b> <?php echo $order_id; ?><br />
                <b>Order Status: </b><?php echo $orderstatus; ?><br />
                <b>Payment Type:</b> <?php echo $payment_type;?><br />
                <b>Payment Amount:</b> <?php echo "$" . $amount;?><br />                        
                <b>First Name:</b> <?php echo $first_name;?><br />          
                <b>Last Name:</b> <?php echo $last_name;?><br />         
                <b>Payment Date:</b> <?php echo $payment_date;?><br />    
                <br />
                <form action="./orderdetails.php" name="getorder" id ="getorder" method="POST">
                <input type="hidden" name="limit" value="<?php echo $limit;?>" />
                <input type="hidden" name="page" value="<?php echo $page;?>" />   
                <input type="hidden" name="order_id" value="<?php echo $order_id;?>"> 
                <input type="submit" name="submit" value="Get This Order">

                </form>
                </div> 
<?php           
            }
            if($Item_Count == 0)
            {
                echo '<b>No Items Found For This Date</b><br /><br />';
            }
            else
            {
                echo $Pagination->getEmbeddedCssStyling();    
                $Pagination->getPaginationLinkBar();                
            }
            
        }   
    }


    if($_GET['order_command']=="getordersbyname")
    {   
        $limit = $_GET['limit'];
        $page = $_GET['page'];
        ?>
        
        <b>Get Order By Name</b><br />
        <div class="leftfloatbar">   
        <b>First Name:</b><br />
        <form action="orders.php" method="GET" id=getpaymentbyfirstname">
        <input type="hidden" name="order_command" id="order_command" value="getordersbyname">
        <input type="hidden" name="limit" value="<?php echo $limit; ?>" />
        <input type="hidden" name="page" value="<?php echo $page; ?>" />
        <input type="text" name="first_name" id="first_name"><br />
        <b>Last Name:</b><br />
        <input type="text" name="last_name" id="last_name"><br />
        <input type="submit" value="submit">
        </form>
        </div>
        <br /><br /><br /><br /><br /><br /><br /><br />
        <?php
        if(isset($_GET['first_name']) && isset($_GET['last_name']))
        {
            
            
            $limit = $_GET['limit'];
            $page = $_GET['page'];
            $first_name = $_GET['first_name'];
            $last_name = $_GET['last_name'];
            $targetPage = "orders.php";
            $getrequest = new payment();
            $getrequest->limit = $limit;
            $getrequest->page = $page;      
            $getrequest->first_name = $first_name;
            $getrequest->last_name = $last_name;
            $getresponse = $getrequest->getpaymentbyname();
            $xml = new SimpleXMLElement($getresponse);
            
            if($xml->Item_Count !=0)
            {   
                
                $Pagination = new Pagination();
                $Pagination->setLimit($limit);
                $Pagination->setPage($page);
                $Pagination->setTargetPage($targetPage);
                $Pagination->setTotalItems($xml->Item_Count);
                $Pagination->addToUrlVarArray("order_command=getordersbyname");
                $Pagination->addToUrlVarArray("limit=$limit");
                $Pagination->addToUrlVarArray("Page=$page");
                $Pagination->addToUrlVarArray("first_name=$first_name");
                $Pagination->addToUrlVarArray("last_name=$last_name");
                $Pagination->setUrlVariables();
                
                print "<b>Order By First/Last Name</b><br /><br />";
                foreach($xml->Item as $itemcount)
                {
                    $order_id = $itemcount->order_id;
                    $first_name = $itemcount->first_name;
                    $payment_type = $itemcount->payment_type;
                    $last_name = $itemcount->last_name;
                    $amount = (double)$itemcount->amount;
                    $amount = number_format($amount, 2, '.', '');   
                    $email = $itemcount->email;
                    $payment_date = $itemcount->payment_date;
                    ?>
                    <div class="doubleborderrightmargin">
                    <b>Order_ID:</b> <?php echo $order_id; ?><br />
                    <b>Payment Type:</b> <?php echo $payment_type;?><br />
                    <b>Payment Amount:</b> <?php echo "$" . $amount;?><br />                        
                    <b>First Name:</b> <?php echo $first_name;?><br />          
                    <b>Last Name:</b> <?php echo $last_name;?><br />         
                    <b>Payment Date:</b> <?php echo $payment_date;?><br />    

                    <form action="./orderdetails.php" method="POST">
                    <input type="hidden" name="order_command" value="getorderbyorderid">
                    <input type="hidden" name="order_id" value="<?php echo $order_id;?>"> 
                    <input type="submit" name="submit" value="Get This Order">
                    </form>
                    </div>  
                
                <?php 
                } 
                echo $Pagination->getEmbeddedCssStyling();
                $Pagination->getPaginationLinkBar(); 
            }
       
        }  
        
    }  
}



?>
</div> 

<br /> 
<br />
</body>
</html>       
 
